google.load('visualization', '1', {'packages':['corechart']});
  var chart = null;
  var dataBar = null;
  var dataArray=Array(0);
  var BioGraphMap=null;
  var BioGraphMarker=null;

function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request.responseText, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

function SetBioChart(params,fltvalue,flttype,depthv)
{
    $("#GraphBio_Bar").html('<div style="height: 100%; width: 100%; background: url(/images/loading/loading9.gif) 45% 50% no-repeat">  </div>');

delGraphMarker();

    var ul="";
            ul="http://" + location.hostname + "/map/Biographdata?search=" + params+"flg_graph_filter"+flttype+"flg_graph_filter"+fltvalue+"flg_graph_filter"+depthv;

    downloadUrl(url = ul, function(returnVal) {
        
        var rawData = returnVal.split("|");
          dataBar = new google.visualization.DataTable();
         dataBar.addColumn('string', 'Location');
         var chkRow="";
         var counter=-1;
        var cIndex;
        var Dataval;
        var yearsum=0;
        var fntSize=0;
        var txtColor="";
            for(var rdata=0; rdata<=rawData.length-2;rdata++)
                {
                  Dataval = rawData[rdata].split(":");
                 if (flttype=="location" || flttype=="o.location" )
                     {
                         if (chkRow!=Dataval[1])
                             {
                                 counter++;
                                 dataBar.addRow();
                                 chkRow=Dataval[1];
                                 dataBar.setCell(counter, 0,Dataval[1],"Location: "+Dataval[1]);
                                 dataArray[counter]=Dataval;

                             }


                cIndex=chkcol(Dataval[0]);
                if (cIndex==false)
                    {

                        dataBar.setCell(counter, addcolum(Dataval[0]),parseFloat(Dataval[2]),parseFloat(Dataval[2])+"\n"+"Date: "+Dataval[7]+"\n"+"Remarks: "+Dataval[6]);


                    }
                else
                    {
                        dataBar.setCell(counter,cIndex ,parseFloat(Dataval[2]),parseFloat(Dataval[2])+"\n"+"Date: "+Dataval[7]+"\n"+"Remarks: "+Dataval[6]);
                    }
fntSize=0;
txtColor='white';
                     }
                 else if (flttype=="year" || flttype=="o.observationdate")
                     {
                         if (chkRow!=Dataval[5])
                             {
                                 counter++;
                                 dataBar.addRow();
                                 chkRow=Dataval[5];
                                 dataBar.setValue(counter, 0,Dataval[5]);
                                 dataArray[counter]=Dataval;

                             }
                     
                   cIndex=chkcol(Dataval[0]);

                if (cIndex==false)
                    {

                        yearsum=parseFloat(Dataval[2]);
                        dataBar.setValue(counter, addcolum(Dataval[0]),parseInt(yearsum));


                    }
                else
                    {
                        yearsum=yearsum + parseFloat(Dataval[2]);
                        dataBar.setValue(counter,cIndex ,parseInt(yearsum));

                    }
                    fntSize=10;
txtColor='#5375ab';
                     }
                
                
                
                

                }

//return;



         chart = new google.visualization.ColumnChart(document.getElementById('GraphBio_Bar'));
         google.visualization.events.addListener(chart, 'onmouseover', function(e) {

             

            
                delGraphMarker();

if (flttype=="location" || flttype=="o.location" )
    {zoomLocation(dataArray[e.row][3],dataArray[e.row][4]);
                var myLatlng = new google.maps.LatLng(dataArray[e.row][3],dataArray[e.row][4]);



        BioGraphMarker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          icon:"/images/target.png"
        });
    }




    });

        chart.draw(dataBar, {
chartArea:{left:50,top:15,width:"95%",height:document.getElementById("GraphBio_Bar").style.height},
fontSize: 10,
gridlineColor:	"#dbe6ec",
legend:'bottom',
legendTextStyle: {color: '#5375ab'},
isStacked:'true',
vAxis: {title: 'Numbers',titleTextStyle: {color: '#5375ab'},textStyle:{color:'#5375ab'}},
backgroundColor: {strokeWidth:0},
axisTitlesPosition:'out',
hAxis:{textStyle:{color:txtColor,fontSize:fntSize}}
                         });



});




}


function SetBioChartCluster()
{//alert(clusterdata.length + "asdasd");
    

    for (var a=0; a<=clusterdata.length-1;a++)
        {
         //  $("#tdtestresult").html($("#tdtestresult").html()+clusterdata[a][0]+"__") ;
        }



//
//    var ul="";
//            ul="http://" + location.hostname + "/map/Biographdata?search=" + params+"flg_graph_filter"+flttype+"flg_graph_filter"+fltvalue+"flg_graph_filter"+depthv;
//
//    downloadUrl(url = ul, function(returnVal) {
//
//        var rawData = returnVal.split("|");
//          dataBar = new google.visualization.DataTable();
//         dataBar.addColumn('string', 'Location');
//         var chkRow="";
//         var counter=-1;
//        var cIndex;
//        var Dataval;
//        var yearsum=0;
//        var fntSize=0;
//        var txtColor="";
//            for(var rdata=0; rdata<=rawData.length-2;rdata++)
//                {
//                  Dataval = rawData[rdata].split(":");
//                 if (flttype=="location" || flttype=="o.location" )
//                     {
//                         if (chkRow!=Dataval[1])
//                             {
//                                 counter++;
//                                 dataBar.addRow();
//                                 chkRow=Dataval[1];
//                                 dataBar.setValue(counter, 0,Dataval[1]);
//                                 dataArray[counter]=Dataval;
//
//                             }
//
//
//                cIndex=chkcol(Dataval[0]);
//                if (cIndex==false)
//                    {
//
//                        dataBar.setValue(counter, addcolum(Dataval[0]),parseFloat(Dataval[2]));
//
//
//                    }
//                else
//                    {
//                        dataBar.setValue(counter,cIndex ,parseFloat(Dataval[2]));
//                    }
//fntSize=0;
//txtColor='white';
//                     }
//                 else if (flttype=="year" || flttype=="o.observationdate")
//                     {
//                         if (chkRow!=Dataval[5])
//                             {
//                                 counter++;
//                                 dataBar.addRow();
//                                 chkRow=Dataval[5];
//                                 dataBar.setValue(counter, 0,Dataval[5]);
//                                 dataArray[counter]=Dataval;
//
//                             }
//
//                   cIndex=chkcol(Dataval[0]);
//
//                if (cIndex==false)
//                    {
//
//                        yearsum=parseFloat(Dataval[2]);
//                        dataBar.setValue(counter, addcolum(Dataval[0]),parseInt(yearsum));
//
//
//                    }
//                else
//                    {
//                        yearsum=yearsum + parseFloat(Dataval[2]);
//                        dataBar.setValue(counter,cIndex ,parseInt(yearsum));
//
//                    }
//                    fntSize=10;
//txtColor='#5375ab';
//                     }
//
//
//
//
//
//                }
//
////return;
//
//
//
//         chart = new google.visualization.ColumnChart(document.getElementById('GraphBio_Bar'));
//         google.visualization.events.addListener(chart, 'onmouseover', function(e) {
//
//
//
//            zoomLocation(dataArray[e.row][3],dataArray[e.row][4]);
//                delGraphMarker();
//if (flttype=="location" || flttype=="o.location" || flttype=="year" || flttype=="o.observationdate" )
//    {
//                var myLatlng = new google.maps.LatLng(dataArray[e.row][3],dataArray[e.row][4]);
//
//
//
//        BioGraphMarker = new google.maps.Marker({
//          position: myLatlng,
//          map: map,
//          icon:"/images/target.png"
//        });
//    }
//
//
//
//
//    });
//
//        chart.draw(dataBar, {
//chartArea:{left:50,top:15,width:"95%",height:document.getElementById("GraphBio_Bar").style.height},
//fontSize: 10,
//gridlineColor:	"#dbe6ec",
//legend:'bottom',
//legendTextStyle: {color: '#5375ab'},
//isStacked:'true',
//vAxis: {title: 'Numbers',titleTextStyle: {color: '#5375ab'},textStyle:{color:'#5375ab'}},
//backgroundColor: {strokeWidth:0},
//axisTitlesPosition:'out',
//hAxis:{textStyle:{color:txtColor,fontSize:fntSize}}
//                         });
//
//
//
//});




}



function SetNonBioChart(params,fltvalue,flttype,depthv,unitv)
{

$("#GraphBio_Bar").html('<div style="height: 100%; width: 100%; background: url(/images/loading/loading9.gif) 45% 50% no-repeat">  </div>');
delGraphMarker();

    var ul="";
            ul="http://" + location.hostname + "/map/Nonbiographdata?search=" + params+"flg_graph_filter"+flttype+"flg_graph_filter"+fltvalue+"flg_graph_filter"+depthv+"flg_graph_filter"+unitv;
    downloadUrl(url = ul, function(returnVal) {
        var TitleName="";
        var rawData = returnVal.split("|");
          dataBar = new google.visualization.DataTable();
         dataBar.addColumn('number', 'Depth');
         
        
         
         var chkRow=-1;
         var counter=-1;
         var minyear=0;
         var maxyear=0;
         var cIndex;
         
            for(var rdata=0; rdata<=rawData.length-2;rdata++)
                {
                 var Dataval = rawData[rdata].split(":");
                 TitleName=Dataval[0];
                 
                 if (flttype=="observationdepth" || flttype=="od.observationdepth" )
                     {
   
                       if (chkRow!= parseFloat(Dataval[6]))
                             {
                                 counter++;
                                 dataBar.addRow();
                                 chkRow=Dataval[1];
                                 dataBar.setCell(counter, 0,parseFloat(Dataval[6]),"Depth: "+ Dataval[6]+" ("+Dataval[8]+")");
                                 dataArray[counter]=Dataval;

                             }
                                  cIndex=chkcol(Dataval[1]);
                            if (cIndex==false)
                                {

                                    dataBar.setCell(counter, addcolum(Dataval[1]),parseFloat(Dataval[2]),TitleName + ": "+ Dataval[2]+"("+Dataval[7]+")"+"\n"+"Date: "+Dataval[9]+"\n"+"Remarks: "+Dataval[10]);


                                }
                            else
                                {
                                    dataBar.setCell(counter,cIndex ,parseFloat(Dataval[2]),TitleName + ": "+ Dataval[2]+"("+Dataval[7]+")"+"\n"+"Date: "+Dataval[9]+"\n"+"Remarks: "+Dataval[10]);
                                }

                                 
                                 
                             
                     }
                 else if (flttype=="year" || flttype=="o.observationdate")
                     {
if (rdata==0){minyear=parseInt(Dataval[5]);}
if (rdata==rawData.length-2){maxyear=parseInt(Dataval[5]);}

                          if (chkRow!= parseFloat(Dataval[6]))
                             {
                                 counter++;
                                 dataBar.addRow();
                                 chkRow=Dataval[1];
                                 dataBar.setCell(counter, 0,parseFloat(Dataval[6]),"Depth: "+ Dataval[6]+" ("+Dataval[8]+")");
                                 dataArray[counter]=Dataval;

                             }
                                  cIndex=chkcol(Dataval[5]);
                            if (cIndex==false)
                                {

                                    dataBar.setCell(counter, addcolum(Dataval[5]),parseFloat(Dataval[2]),"Depth: "+ Dataval[6]+" ("+Dataval[8]+")\n"+TitleName + ": "+ Dataval[2]+"("+Dataval[7]+")");


                                }
                            else
                                {
                                    dataBar.setCell(counter,cIndex ,parseFloat(Dataval[2]),"Depth: "+ Dataval[6]+" ("+Dataval[8]+")\n"+TitleName + ": "+ Dataval[2] +"("+Dataval[7]+")");
                                }

                         
                     }


                
    

                }
             
//if(minyear==maxyear && minyear>0 && maxyear>0){minyear=minyear; maxyear=maxyear+2}
         chart = new google.visualization.ScatterChart(document.getElementById('GraphBio_Bar'));

         google.visualization.events.addListener(chart, 'onmouseover', function(e) {



            
                delGraphMarker();
if (flttype=="observationdepth" || flttype=="od.observationdepth" )
    {zoomLocation(dataArray[e.row][3],dataArray[e.row][4]);
                var myLatlng = new google.maps.LatLng(dataArray[e.row][3],dataArray[e.row][4]);



        BioGraphMarker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          icon:"/images/target.png"
        });
    }




    });
        chart.draw(dataBar, {chartArea:{left:50,top:15,width:"95%",height:document.getElementById("GraphBio_Bar").style.height},
fontSize: 10,
gridlineColor:	"#dbe6ec",
legend:'bottom',
legendTextStyle: {color: '#5375ab'},
vAxis: {title: 'Numbers',titleTextStyle: {color: '#5375ab'},textStyle:{color:'#5375ab'}},
backgroundColor: {strokeWidth:0},
axisTitlesPosition:'out',
hAxis:{title:'Depth',textStyle:{color:'5375ab'}}//,minValue:minyear, maxValue:maxyear,format:'#'
                         });


                         //gvTooltip("GraphBio_Bar","dataBar",chart,"{maxWidth: '200px', style: 'clean'}");



});




}






function chkcol(cname)
{
    for (var a=0; a<=dataBar.getNumberOfColumns()-1;a++)
        {
            if (dataBar.getColumnLabel(a)==cname)
                {
                    return a;
                }
        }
        return false;

}



function addcolum(spname)
{
    return dataBar.addColumn('number', spname);
}
function delGraphMarker()
{
    if (BioGraphMarker!=null)
            {
        BioGraphMarker.setMap(null);

        BioGraphMarker = null;
            }
}


